<template>
	<view class="index">
		<MusicHead title='网易云音乐' :icon='false'></MusicHead>
		<view class="container">
			<!-- uniapp内置的滚动组件 -->
			<scroll-view scroll-y="true" >
				<!-- 搜索框 -->
				<view class="index-search" @tap='handleToSearch'>
					<text class="iconfont icon-Magnifier"></text>
					<input type="text" placeholder="搜索歌曲" />
				</view>
				<!-- 榜单 -->
				<view class="index-list">
					<view class="index-list-item" v-for="i in topList" :key='i.id' @tap="handleToList(i.id)">
						<!-- 封面图 -->
						<view class="index-list-img">
							<image :src="i.coverImgUrl"></image>
							<text>{{i.updateFrequency}}</text>
						</view>
						<!-- 排名靠前的歌曲信息 -->
						<view class="index-list-text">
							<view  v-for="(j,index) in i.tracks" :key='index'>
								{{index+1}}.{{j.first}} - {{j.second}}
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>		
	</view>
</template>

<script>
	import '@/common/iconfont.css';
	import MusicHead from '../../components/musichead/MusicHead.vue';
	import {getTopList} from '../../common/api.js'
	
	export default {
		name:'Index',
		components:{
			MusicHead
		},
		data() {
			return {
				topList:[]
			}
		},
		onLoad() {
			getTopList().then((res)=>{
				if(res.length){
					this.topList=res[1].data.list.slice(0,4)
				}
			});
		},
		methods: {
			// 跳转到榜单详情页，要传参listId
			handleToList(id){
				uni.navigateTo({
					url:'/pages/list/list?listId='+id
				})
			},
			handleToSearch(){
				uni.navigateTo({
					url:'/pages/search/search'
				})
			}
		}
	}
</script>

<style scoped>
	.index{}
	.index-search{
		display: flex;
		align-items: center;
		height: 70rpx;
		margin: 70rpx 30rpx 30rpx 30rpx;
		background: #F7F7F7;
		border-radius: 50rpx;
	}
	.index-search text{
		font-size: 28rpx;
		margin-right: 26rpx;
		margin-left: 28rpx;
	}
	.index-search input{
		font-size: 28rpx;
		flex: 1;
	}
	.index-list{
		margin: 0 30rpx;
	}
	.index-list-item{
		display: flex;
		margin-bottom: 34rpx;
	}
	.index-list-img{
		width: 212rpx;
		height: 212rpx;
		position: relative;
		border-radius: 30rpx;
		overflow: hidden;
		margin-right: 22rpx;
	}
	.index-list-img image{
		width: 100%;
		height: 100%;
	}
	.index-list-img text{
		position: absolute;
		bottom: 14rpx;
		left: 12rpx;
		color: white;
		font-size: 20rpx;
	}
	.index-list-text{
		font-size: 24rpx;
		line-height: 66rpx;
	}
	.index-list-text view{
		/* 如果要做溢出处理的话，必须指定宽度（块级元素）or高度（行级元素） */
		width: 420rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}
</style>
